/*
**抽象日志类
*/

#pragma once

#include <atomic>
#include <cstdint>
#include <string>
#include <thread>
#include <memory>

namespace lxz
{

    enum log_level
    {
        LOG_LEVEL_DEBUG,
        LOG_LEVEL_INFO,
        LOG_LEVEL_WARN,
        LOG_LEVEL_ERR,
    };

    enum log_type
    {
        LOG_TYPE_NONE,
        LOG_TYPE_SINGLE_FILE,
        LOG_TYPE_CHUNK_FILE,
        LOG_TYPE_ROLL_FILE,
        LOG_TYPE_STDOUT,
    };

    class abstract_loger
    {
    public:
        abstract_loger()
            : level_(LOG_LEVEL_DEBUG), looping_(false), thread_(nullptr)
        {
        }
        virtual ~abstract_loger()
        {
        }

        // 通用添加日志到队列的方法
        virtual int32_t append(log_level level, std::string log) = 0;

        log_level get_level(void)
        {
            return level_;
        }

    protected:
        log_level level_; // 日志等级

        std::atomic_bool looping_;
        std::shared_ptr<std::thread> thread_; // flush

    protected:
        // 写日志线程函数
        virtual void flush(void) = 0;
    };

}